package com.jf.mall.domain;

import java.math.BigDecimal;
import java.util.Date;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-10-02
 * Time:3:53
 */
public class Commodity {
    /*
    1.id
    2.用户id
    3.家具id
    4.家具名
    5.单价
    6.数量
    7.总价
    8.图片
    9.商品更新时间(添加/修改会改变)
     */
    private int id;
    private Integer userId;
    private Integer furnitureId;
    private String name;
    private BigDecimal unitPrice;
    private Integer count;
    private BigDecimal totalPrice;
    private String imgPath;
    private Date updateTime;

    public Commodity() {
    }

    public Commodity(Integer userId, Furniture furniture) {
        this.userId = userId;
        this.furnitureId = furniture.getId();
        this.name = furniture.getName();
        this.unitPrice = furniture.getPrice();
        count = 1;
        totalPrice = furniture.getPrice();
        this.imgPath = furniture.getImgPath();
    }


    public Commodity(Integer userId, Integer furnitureId, String name, BigDecimal unitPrice, Integer count, BigDecimal totalPrice, String imgPath) {
        this.userId = userId;
        this.furnitureId = furnitureId;
        this.name = name;
        this.unitPrice = unitPrice;
        this.count = count;
        this.totalPrice = totalPrice;
        this.imgPath = imgPath;
    }

    public int getId() {
        return id;
    }

    public Integer getUserId() {
        return userId;
    }

    public Integer getFurnitureId() {
        return furnitureId;
    }

    public String getName() {
        return name;
    }

    public BigDecimal getUnitPrice() {
        return unitPrice;
    }

    public Integer getCount() {
        return count;
    }

    public BigDecimal getTotalPrice() {
        return totalPrice;
    }

    public String getImgPath() {
        return imgPath;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public void setFurnitureId(Integer furnitureId) {
        this.furnitureId = furnitureId;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setUnitPrice(BigDecimal unitPrice) {
        this.unitPrice = unitPrice;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public void setTotalPrice(BigDecimal totalPrice) {
        this.totalPrice = totalPrice;
    }

    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    protected void add() {
        count++;
    }

    protected void update(Furniture furniture) {
        this.name = furniture.getName();
        this.unitPrice = furniture.getPrice();
        totalPrice = unitPrice.multiply(new BigDecimal(count));
        imgPath = furniture.getImgPath();
    }

    protected void updateCount(int count) {
        if (count != 0) {
            this.count = count;
            totalPrice = unitPrice.multiply(new BigDecimal(count));
        }
    }
}
